hysop.fields.cartesian_discrete_field module¶
Discrete fields (scalars or vectors) descriptions.
* CartesianDiscreteScalarFieldViewContainerI
* CartesianDiscreteScalarField
* CartesianDiscreteTensorField
* CartesianDiscreteScalarFieldView
Documentation and examples can be found in Continuous and discrete fields.
- hysop.fields.cartesian_discrete_field.CartesianDiscreteField = (<class 'hysop.fields.cartesian_discrete_field.CartesianDiscreteScalarField'>, <class 'hysop.fields.cartesian_discrete_field.CartesianDiscreteTensorField'>)¶
A CartesianDiscreteField is either of CartesianDiscreteScalarField or a CartesianDiscreteTensorField
- class hysop.fields.cartesian_discrete_field.CartesianDiscreteScalarField(field, topology, init_topology_state=None, allocate_data=True, **kwds)[source]¶
Bases:
CartesianDiscreteScalarFieldView
,DiscreteScalarField
Discrete representation of cartesian scalar or vector fields, handling distributed (mpi) data (hysop.core.arrays.array.Array) wich are numpy like multidimensional arrays defined on various array backends (numpy, OpenCL, …).
A CartesianDiscreteScalarField is a Field discretized on a Box (on a regular multi-dimensional grid) trough a CartesianTopology.
Create and initialize a CartesianDiscreteScalarField from a Field and a CartesianTopology.
- Parameters:
field (
Field
) – The continuous field that is dicrerized.topology (
CartesianTopology
) – The topology where to allocate the discrete field.init_state (
hysop.topology.cartesian_topology.CartesianTopologyState
) – The init topology state (transposition state for field initialization, optional).kwds (dict) – Base class arguments.
- data¶
Actual n-dimensional arrays of data (immutable), one per component.
- Type:
tuple of
hysop.core.arrays.array.Array
- buffers¶
Return Array’s data buffers. buffers are the lower level representation of data without any hysop wrapping, usefull to use with external libraries. May return the same a data().
- Type:
tuple of buffers, numpy.ndarray or pyopencl.buffers
Notes
To modify data inplace use field.data[component_id][…] = …
DiscreteScalarField.data = (arr0,arr1,arr2,…), DiscreteScalarField.data[0] = arr0 and DiscreteScalarField._set_data(…) are equivalent and will perfom a full copy of the arrays..
There is currenltly no way to swap data between discrete fields.
If topology state is read-only, data view may be a constant view depending on the backend view capabilities (this is the default state for operator input variables).
- static __new__(cls, field, topology, init_topology_state=None, allocate_data=True, **kwds)[source]¶
Create and initialize a CartesianDiscreteScalarField from a Field and a CartesianTopology.
- Parameters:
field (
Field
) – The continuous field that is dicrerized.topology (
CartesianTopology
) – The topology where to allocate the discrete field.init_state (
hysop.topology.cartesian_topology.CartesianTopologyState
) – The init topology state (transposition state for field initialization, optional).kwds (dict) – Base class arguments.
- data¶
Actual n-dimensional arrays of data (immutable), one per component.
- Type:
tuple of
hysop.core.arrays.array.Array
- buffers¶
Return Array’s data buffers. buffers are the lower level representation of data without any hysop wrapping, usefull to use with external libraries. May return the same a data().
- Type:
tuple of buffers, numpy.ndarray or pyopencl.buffers
Notes
To modify data inplace use field.data[component_id][…] = …
DiscreteScalarField.data = (arr0,arr1,arr2,…), DiscreteScalarField.data[0] = arr0 and DiscreteScalarField._set_data(…) are equivalent and will perfom a full copy of the arrays..
There is currenltly no way to swap data between discrete fields.
If topology state is read-only, data view may be a constant view depending on the backend view capabilities (this is the default state for operator input variables).
- property is_tmp¶
Is this DiscreteScalarField temporary ?
- property mem_tag¶
- class hysop.fields.cartesian_discrete_field.CartesianDiscreteScalarFieldView(dfield, topology_state, **kwds)[source]¶
Bases:
CartesianDiscreteScalarFieldViewContainerI
,DiscreteScalarFieldView
View over a CartesianDiscreteScalarField.
Initialize a CartesianDiscreteScalarFieldView on given discrete cartesian field with given cartesian topology state.
- Parameters:
dfield (
hysop.fields.cartesian_discrete_field.CartesianDiscreteScalarField
) – The discrete field this view is on.topology_state (
hysop.topology.cartesian.CartesianTopologyState
) – The topology state of this view (optional).kwds (dict) – Base class arguments.
- static __new__(cls, dfield, topology_state, **kwds)[source]¶
Initialize a CartesianDiscreteScalarFieldView on given discrete cartesian field with given cartesian topology state.
- Parameters:
dfield (
hysop.fields.cartesian_discrete_field.CartesianDiscreteScalarField
) – The discrete field this view is on.topology_state (
hysop.topology.cartesian.CartesianTopologyState
) – The topology state of this view (optional).kwds (dict) – Base class arguments.
- accumulate_ghosts(**kwds)[source]¶
Exchange ghosts using cached ghost exchangers which are built at first use. ie. Exchange every ghosts components of self.data using current topology state. Specialization for ghost summation.
Defaults to ghost accumulation excluding diagonals.
- property all_inner_ghost_slices¶
Return collection of slices and shapes describing all possible combinations of inner ghosts slices in this array as local indices.
Those slices corresponds to local to process ghosts (ie. ghosts that may be sent to other neighbor processes, including diagonal procecess, during a ghosts exchange).
- Return a dictionnary {ndirections} (number of directions intersected)
- -> {directions} (0=first axis, …, dim-1=last axis)
- -> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)
-> (view, shape)
- property all_inner_ghost_slices_per_ncenters¶
Compute the collection of slices describing all possible combinations of inner ghosts slice in this array as local indices like self.get_all_local_inner_ghost_slices() and sort them by number of centers (number of displacement == 0).
- Return a list [ndirections] (number of directions intersected)
- [ncenters] (number of null displacements)
- -> {directions} (0=first axis, …, dim-1=last axis)
- -> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)
-> (view,shape)
‘all’ -> tuple of all views and shapes up to this depth
- property all_outer_ghost_slices¶
Return collection of slices and shapes describing all possible combinations of outer ghosts slices in this array as local indices.
Those slices corresponds to local to process ghosts (ie. ghosts that may be received from other neighbor processes, including diagonal processes, during a ghosts exchange).
- Return a dictionnary {ndirections} (number of directions intersected)
- -> {directions} (0=first axis, …, dim-1=last axis)
- -> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)
-> (view, shape)
- property all_outer_ghost_slices_per_ncenters¶
Compute the collection of slices describing all possible combinations of outer ghosts slice in this array as local indices like self.get_all_local_outer_ghost_slices() and sort them by number of centers (number of displacement == 0).
- Return a list [ndirections] (number of directions intersected)
- [ncenters] (number of null displacements)
- -> {directions} (0=first axis, …, dim-1=last axis)
- -> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)
-> (view,shape)
‘all’ -> tuple of all views and shapes up to this depth
- as_any_dfield(memory_order, **kwds)[source]¶
Quickly take a view on this DiscreteScalarFieldView using self topology state supplemented by a MemoryOrdering.
- property axes¶
Return the permutation scheme in numpy notations.
- property buffers¶
Return all array data as a buffers as a tuple.
- build_ghost_exchanger(name=None, components=None, directions=None, data=None, ghosts=None, ghost_op=None, ghost_mask=None, exchange_method=None)[source]¶
Build a ghost exchanger for cartesian discrete fields, possibly on different data.
- clone(name=None, pretty_name=None, var_name=None, latex_name=None, tstate=None)[source]¶
Create a DiscreteScalarField and allocate it like the current object, possibly on a different backend.
This should only be used for debugging and testing purpose. The generated discrete field is registered to a cloned continuous field.
- property compute_coords¶
Get local mesh physical coordinates in each direction (excluding ghosts).
- property compute_mesh_coords¶
Get local mesh physical coordinates in each direction (excluding ghosts). Same as self.compute_coords but with all sequences as nd arrays and reversed. Returned coordinates are x,y,z,…) instead of (…,z,y,x).
- property compute_resolution¶
Get compute resolution (mesh size without ghosts) on local discrete field mesh.
- property compute_slices¶
Return a tuple of slices indexing the local compute mesh.
- property coords¶
Get local mesh physical coordinates in each direction (including ghosts).
- copy(from_dfield, compute_slices=False, **kwds)[source]¶
Initialize a field on topo with values from another field.
- Parameters:
from_dfield (
fields.discrete_field.CartesianDiscreteScalarFieldView
or Array or buffer-like) – Source data that is copied to self.compute_slices (bool, optional, defaults to False) – If set to True, apply compute slice to self and from_dfield (if from_dfield is a CartesianDiscreteScalarFieldView), prior to copy.
- property data¶
Return contained array as a tuple.
- distance(other, **kwds)[source]¶
Compute the distance between two discrete fields
- p-distance = (sum(|data[d]|**p)**1/p for d = 1..dim
where data[d] = |self.data[d] - other.data[d]| summed on all grid points excluding ghosts.
See CartesianDiscreteScalarField.norm() for keywords parameters.
- exchange_ghosts(components=None, directions=None, ghosts=None, ghost_op=None, ghost_mask=None, exchange_method=None, evt=None, build_exchanger=False, build_launcher=False, **kwds)[source]¶
Exchange ghosts using cached ghost exchangers which are built at first use. ie. Exchange every ghosts components of self.data using current topology state.
Defaults to full ghosts exchange, including diagonals (ie. overwrite operation).
- get_all_inner_ghost_slices(*args, **kwds)[source]¶
Return collection of slices and shapes describing all possible combinations of inner ghosts slices in this array as local indices.
Those slices corresponds to local to process ghosts (ie. ghosts that may be sent to other neighbor processes, including diagonal procecess, during a ghosts exchange).
- Return a dictionnary {ndirections} (number of directions intersected)
- -> {directions} (0=first axis, …, dim-1=last axis)
- -> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)
-> (view, shape)
- get_all_inner_ghost_slices_per_ncenters(*args, **kwds)[source]¶
Compute the collection of slices describing all possible combinations of inner ghosts slice in this array as local indices like self.get_all_local_inner_ghost_slices() and sort them by number of centers (number of displacement == 0).
- Return a list [ndirections] (number of directions intersected)
- [ncenters] (number of null displacements)
- -> {directions} (0=first axis, …, dim-1=last axis)
- -> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)
-> (view,shape)
‘all’ -> tuple of all views and shapes up to this depth
- get_all_outer_ghost_slices(*args, **kwds)[source]¶
Return collection of slices and shapes describing all possible combinations of outer ghosts slices in this array as local indices.
Those slices corresponds to local to process ghosts (ie. ghosts that may be received from other neighbor processes, including diagonal processes, during a ghosts exchange).
- Return a dictionnary {ndirections} (number of directions intersected)
- -> {directions} (0=first axis, …, dim-1=last axis)
- -> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)
-> (view, shape)
- get_all_outer_ghost_slices_per_ncenters(*args, **kwds)[source]¶
Compute the collection of slices describing all possible combinations of outer ghosts slice in this array as local indices like self.get_all_local_outer_ghost_slices() and sort them by number of centers (number of displacement == 0).
- Return a list [ndirections] (number of directions intersected)
- [ncenters] (number of null displacements)
- -> {directions} (0=first axis, …, dim-1=last axis)
- -> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)
-> (view,shape)
‘all’ -> tuple of all views and shapes up to this depth
- get_inner_ghost_slices(*args, **kwds)[source]¶
Return a tuple of tuples of slices indexing the local inner ghosts. Those slices corresponds to neighbour processes overlap on local compute slices, EXCLUDING diagonal neighbour processes ghost overlaps. See CartesianMesh.get_local_inner_ghost_slices().
- get_outer_ghost_slices(*args, **kwds)[source]¶
Return a tuple of tuples of slices indexing the local outer ghosts. Those slices corresponds to local to process ghosts, EXCLUDING diagonal neighbour processes ghost overlaps. See CartesianMesh.get_local_outer_ghost_slices().
- property ghosts¶
Get the number of ghosts per direction on local discrete field mesh.
- property global_boundaries¶
Return global boundaries as a tuple of left and right boundaries.
- property global_boundaries_config¶
Return global boundaries configuration (boundary kind + attached data).
- property global_lboundaries¶
Return global left boundaries.
- property global_lboundaries_config¶
Return global left boundaries configuration (boundary kind + attached data).
- property global_rboundaries¶
Return global right boundaries.
- property global_rboundaries_config¶
Return global right boundaries configuration (boundary kind + attached data).
- property grid_npoints¶
Return the effective number of global computational points.
- property inner_ghost_slices¶
Return a tuple of tuples of slices indexing the local inner ghosts. Those slices corresponds to neighbour processes overlap on local compute slices, EXCLUDING diagonal neighbour processes ghost overlaps. See CartesianMesh.get_local_inner_ghost_slices().
- property is_at_boundary¶
Return a numpy boolean mask to identify processes that are on either on the left or on the right of the domain. Processes can be on the left and the right at the same time on direction d if and only if topology.proc_shape[d] == 1. ie. is_at_boundary[d] = True means that process cartesian coordinates is the first or
the lastest on direction d:(proc_coords[d] in [0, proc_shape[d] - 1]).
- property is_at_left_boundary¶
Return a numpy boolean mask to identify processes that are on the left of the domain. ie. is_at_left_boundary[d] = True means that process cartesian coordinates is the first on direction d: topology.proc_coords[d] == 0.
- property is_at_right_boundary¶
Return a numpy boolean mask to identify processes that are on the right of the domain. ie. is_at_right_boundary[d] = True means that process cartesian coordinates
is the lastest on direction d: topology.proc_coords[d] == topology.proc_shape[d] - 1.
- property is_tmp¶
Is this DiscreteScalarField temporary ?
- property local_boundaries¶
Return local boundaries kind as a tuple of left and right boundaries. Boundaries on the interior of the global domain have value BoundaryCondition.NONE.
- property local_lboundaries¶
Return local left boundaries kind. Boundaries on the interior of the global domain have value BoundaryCondition.NONE.
- property local_rboundaries¶
Return local right boundaries kind. Boundaries on the interior of the global domain have value BoundaryCondition.NONE.
- local_slices(ghosts)[source]¶
Return a tuple of slices indexing the local compute mesh, including specified number of ghosts on each axis.
- property mem_tag¶
- property memory_order¶
Return the memory order of underlying data.
- property mesh_coords¶
Get local mesh physical coordinates in each direction (including ghosts). Same as self.coords but with all sequences as nd arrays and reversed. Returned coordinates are x,y,z,…) instead of (…,z,y,x).
- norm(p=2, normalize=True, data=None)[source]¶
Compute a Lp norm of the discrete field.
- Lp-norm = sum(data[d]**p)**(1.0/p) for d = 1..nb_components
summed on all grid points excluding ghosts.
- p¶
Parameter for the Lp-norm. p can be any integer (or float) greater than 0. Infinite norm can be returned by setting p to np.inf. Defaults to the Euclidean norm (p=2).
- property npoints¶
Get resolution (mesh size with ghosts) on local discrete field mesh.
- property outer_ghost_slices¶
Return a tuple of tuples of slices indexing the local outer ghosts. Those slices corresponds to local to process ghosts, EXCLUDING diagonal neighbour processes ghost overlaps. See CartesianMesh.get_local_outer_ghost_slices().
- property periodicity¶
Get periodicity of the global boundaries. This is not to be confused with the cartesian communicator periodicity.
- property resolution¶
Get resolution (mesh size with ghosts) on local discrete field mesh.
- property sbuffer¶
Return container buffer.
- property sdata¶
Return contained array.
- property shape¶
Alias for resolution.
- property size¶
Size of the underlying contiguous data arrays.
- property space_step¶
Get the space step of the discretized mesh grid.
- tmp_dfield_like(name, pretty_name=None, var_name=None, latex_name=None, backend=None, is_read_only=None, initial_values=None, dtype=None, grid_resolution=None, ghosts=None, tstate=None, lboundaries=None, rboundaries=None, register_discrete_field=False, **kwds)[source]¶
Create a new Field and a new temporary CartesianDiscreteScalarField. like the current object, possibly on a different backend. /!The returned discrete field is not allocated.
- property tstate¶
Return the permutation scheme as a hysop.constants.TranspositionState.
- class hysop.fields.cartesian_discrete_field.CartesianDiscreteScalarFieldViewContainerI[source]¶
Bases:
object
- property all_inner_ghost_slices¶
- property all_outer_ghost_slices¶
- property axes¶
- collect_data(component=0, leader=0)[source]¶
Debug function to collect data across multiples processes.
- property compute_buffers¶
Like buffers, but with a view on compute_slices.
- property compute_coords¶
- property compute_data¶
Like data, but with a view on compute_slices.
- property compute_mesh_coords¶
- property compute_resolution¶
- property compute_slices¶
- property coords¶
- distance(other, **kwds)[source]¶
Compute the distance between two discrete fields
- p-distance = (sum(|data[d]|**p)**1/p for d = 1..dim
where data[d] = |self.data[d] - other.data[d]| summed on all grid points excluding ghosts.
See CartesianDiscreteScalarField.norm() for keywords parameters.
- property ghosts¶
- property global_boundaries¶
- property global_lboundaries¶
- property global_rboundaries¶
- property grid_npoints¶
- initialize(formula, vectorize=False, without_ghosts=True, exchange_ghosts=True, exchange_kwds=None, only_finite=True, reorder=None, quiet=False, components=None, **kwds)[source]¶
Initialize the cartesian field data.
- Parameters:
formula (python function or tuple of np.ndarray, optional) – User-defined function of the space coordinates (at least) used to compute field values for each grid poin. Initialize directly from data if a tuple of np.ndarray is supplied.
vectorize (bool, optional) – True if formula must be vectorized (i.e. is of type ‘user_func_2’, see Continuous and discrete fields for details)
without_ghosts (boolean, optional, defaults to False) – Do not initialize ghosts using formula. In this case, ghosts may be initialized by ghost exchange (see next parameter).
exchange_ghosts (bool, optional, defaults to True) – Should we exchange ghosts after initialization ?
exchange_kwds (dict, optional,) – Extra exchange keyword arguments passed to ghost exchange. Only used if exchange_ghosts is set to True.
only_finite (bool, optional) – Check that initialized values are not +inf, -inf or NaN. Defaults to True.
reorder (str or tuple of str, optional) –
Reorder all kwd according to current topology state. ie. kwd should be contained in kwds and kwds[kwd] should
be of length self.domain.dim.
kwds (dict) – Extra keyword arguments passed to formula, optional, depends on passed formula.
- property inner_ghost_slices¶
- property is_at_boundary¶
- property is_at_left_boundary¶
- property is_at_right_boundary¶
- property local_boundaries¶
- property local_lboundaries¶
- property local_rboundaries¶
- local_slices(ghosts)[source]¶
Return a tuple of slices indexing the local compute mesh, including specified number of ghosts on each axis.
- property memory_order¶
- property mesh_coords¶
- norm(p=2, data=None, view=None)[source]¶
Compute a per-component Lp norm of the discrete field.
- Lp-norm = sum(data**p)**(1.0/p)
summed on all grid points excluding ghosts.
- p¶
Parameter for the Lp-norm. p can be any integer (or float) greater than 0. Infinite norm can be returned by setting p to np.inf. Defaults to the Euclidean norm (p=2). If p!=np.inf, the result is scaled by the mesh size.
- data¶
Custom data to apply the norm to. By default this is the local to field data.
- view¶
View on data.
- property outer_ghost_slices¶
- property periodicity¶
- print_with_ghosts(component=0, compute=None, data=None, inner_ghosts=None, outer_ghosts='X', **print_opts)[source]¶
Print values with ghosts replaced by symbol. Mainly for debug purposes.
- property resolution¶
- property space_step¶
- property tstate¶
- class hysop.fields.cartesian_discrete_field.CartesianDiscreteTensorField(field, dfields, name=None, pretty_name=None, latex_name=None, **kwds)[source]¶
Bases:
CartesianDiscreteScalarFieldViewContainerI
,DiscreteTensorField
- class hysop.fields.cartesian_discrete_field.TmpCartesianDiscreteScalarField(**kwds)[source]¶
Bases:
CartesianDiscreteScalarField
Create and initialize a CartesianDiscreteScalarField from a Field and a CartesianTopology.
- Parameters:
field (
Field
) – The continuous field that is dicrerized.topology (
CartesianTopology
) – The topology where to allocate the discrete field.init_state (
hysop.topology.cartesian_topology.CartesianTopologyState
) – The init topology state (transposition state for field initialization, optional).kwds (dict) – Base class arguments.
- data¶
Actual n-dimensional arrays of data (immutable), one per component.
- Type:
tuple of
hysop.core.arrays.array.Array
- buffers¶
Return Array’s data buffers. buffers are the lower level representation of data without any hysop wrapping, usefull to use with external libraries. May return the same a data().
- Type:
tuple of buffers, numpy.ndarray or pyopencl.buffers
Notes
To modify data inplace use field.data[component_id][…] = …
DiscreteScalarField.data = (arr0,arr1,arr2,…), DiscreteScalarField.data[0] = arr0 and DiscreteScalarField._set_data(…) are equivalent and will perfom a full copy of the arrays..
There is currenltly no way to swap data between discrete fields.
If topology state is read-only, data view may be a constant view depending on the backend view capabilities (this is the default state for operator input variables).
- property is_tmp¶
Is this DiscreteScalarField temporary ?